﻿#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//常用的拷贝和替换算法  replace_if
class Replace
{
public:
	bool operator()(int val)
	{
		return val >= 20;
	}
};
class Myprint
{
public:
	void operator()(int val)
	{
		cout << val << "  ";
	}
};
void test01()
{
	vector<int>v;
	v.push_back(10);
	v.push_back(25);
	v.push_back(30);
	v.push_back(20);
	v.push_back(30);
	//将大于等于20的换成2000
	for_each(v.begin(), v.end(), Myprint());
	replace_if(v.begin(), v.end(), Replace(), 2000);
	cout << endl;
	for_each(v.begin(), v.end(), Myprint());
}
int main()
{
	test01();
}